<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    [#include "/includes/header.html" /]
    <script type="text/javascript">
        $(document).ready(function () {
            searchItems();
            $("#myqueryBtn").click(function () {
                searchItems();
            });
        });

        var pageClick = function (pageNo) {
            searchItems(pageNo);
        }

        var searchItems = function (currPage) {
            var params = {};
            //其他查询条件
            if (currPage) {
                params.page = currPage;
            }

            $("#mainTable").mask("加载中...");
            var url = obz.ctx + "/lottery/winlist";
            obz.ajaxJson(url, params, function (resp) {
                var result = resp.data;
                $(".lotteryLotGrid").empty();
                if (currPage) {
                    $("#pager").pager({
                        pagenumber: currPage,
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                } else {
                    $("#pager").pager({
                        recordcount: result.totalRow,
                        pagesize: result.pageSize,
                        recordtext: '共 {0} 页, {1} 条记录',
                        buttonClickCallback: pageClick
                    });
                }
                var dataList = result.list;
                if (dataList.length > 0) {
                    for (var i = 0; i < dataList.length; i++) {
                        var _row = dataList[i];
                        var trHtml = obz.dataTemplate4obj($("#lottery_table_tr_tpl").html(), _row);
                        $(".lotteryLotGrid").append(trHtml);
                    }
                    //初始化checkbox点击事件
                    TBatch.checkCheckbox();
                    TBatch.initCheckboxClick();
                    TBatch.initOptEvent(TableOpt.init());
                } else {
                    $(".lotteryLotGrid").append($("#lottery_table_noresult_tr_tpl").html());
                }

                $("#mainTable").unmask();
            });
        }

        //=============================表格操作事件开始=============================================
        var TableOpt = {

            edit: function (param) {
                var id = param[1], type = param[2];
                if (type == 1) type = "jiugongge";
                else if (type == 2) type = "guaguale";
                else if (type == 3) type = "yaoyiyao";
                else if (type == 4) type = "fanfanle";
                else {
                    BootstrapDialog.alert({title: "提示", message: "亲，未知抽奖活动类型。"});
                    return;
                }
                location.href = obz.ctx + "/lottery/show/" + type + "/" + id;
            },

            del: function (param) {
                obz.showMessage("确定删除吗？删除后不可恢复，请谨慎操作！", function () {
                    var ids = param[1];
                    obz.ajaxJson(obz.ctx + "/lottery/del", {ids: ids}, function (resp) {
                        if (resp.code == 200) {
                            searchItems();
                        } else {
                            var html = "";
                            for (var i = 0; i < resp.data.length; i++) {
                                html += "奖池" + resp.data[i] + "，有绑定活动，请先删除活动<br/>";
                            }
                            obz.showMessage(html, function () {
                                searchItems();
                            });
                        }
                    });
                });
                return false;
            },

            init: function () {
                var optArray = new Array();
                optArray.push(this.edit);
                optArray.push(this.del);
                return optArray;
            }
        }
        //=============================表格操作事件结束=============================================
    </script>
</head>
<body class="fixed-sidebar full-height-layout gray-bg">
[#include "/includes/menus.html" /]
<div class="wrapper wrapper-content">
    <div class="row content-tabs">
        <nav class="page-tabs J_menuTabs">
            <div class="page-tabs-content" style="margin-left: 0px;">
                <a href="${webctx}/qiandao" class="J_menuTab">签到</a>
                <a href="${webctx}/lottery" class="J_menuTab active">抽奖</a>
                <a href="${webctx}/prize" class="J_menuTab">奖品 </a>
            </div>
        </nav>
    </div>
    <div class="tabs-container row" style="padding-top: 12px;">
        <ul class="nav nav-tabs">
            <li><a href="${webctx}/lottery/type">创建抽奖</a></li>
            <li><a href="${webctx}/lottery">管理抽奖</a></li>
            <!-- <li><a href="${webctx}/lottery/joins">参与记录</a></li> -->
            <li class="active"><a href="${webctx}/lottery/wins">中奖情况</a></li>
        </ul>
    </div>
    <div id="tableList" class="row ibox-content">
        <table class="table-striped">
            <tr>
                <td colspan="3" style="text-align: left;">
                    <input type="text" name="q_pond_txt" id="q_pond_txt" class="input-text"
                           style="width:190px; color:#DFDFDF" value="输入奖池名称"
                           onfocus="if(this.value=='输入奖池名称'){this.value=''};this.style.color='black';"
                           onblur="if(this.value==''||this.value=='输入奖池名称'){this.value='输入奖池名称';this.style.color='#DFDFDF';}"/>
                    <button id="myqueryBtn" class="btn btn-success">查询</button>
                </td>
            </tr>
        </table>
        <div id="lotteryToolsbar" class="panel-body">
            <div id="pager" class="jqpager" style="margin-bottom: 1px;"></div>
        </div>
        <table class="table table-striped table-bordered bootstrap-datatable datatable" id="mainTable" border="0">
            <thead>
            <tr>
                <th>
                    <input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/>
                </th>
                <th>
                    <span style="vertical-align: middle;">抽奖名称</span>
                </th>
                <th>中奖用户</th>
                <th>获得奖品</th>
                <th>奖品类型</th>
                <th>奖品数量</th>
            </tr>
            </thead>
            <tbody class="lotteryLotGrid">
            </tbody>
        </table>
    </div>
</div>
<!-- html 模板文件 -->
<script type="text/template" id="lottery_table_tr_tpl">
    <tr class="package">
        <td>
            <input type="checkbox" class="commchk" id="checkbox_{id}"
                   style="margin-right: 4px; vertical-align: middle;"/>
        </td>
        <td>
            <span style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">{lottery_name}</span>
        </td>
        <td>
            {nickname}
        </td>
        <td>
            <span> {prize_name} </span>
        </td>
        <td>{type_name}</td>
        <td>
            {prize_single_cash}
        </td>
    </tr>
</script>
<script type="text/template" id="lottery_table_noresult_tr_tpl">
    <tr class="package">
        <td class="center" colspan="6">
            还没有买家中奖
        </td>
    </tr>
</script>
[#include "/includes/footer.html" /]
<script>
    Template.init("#menu-qiandao");
</script>
</body>
</html>